from django.test import TestCase


# Create your tests here.


class People:
    country = '中国'  # 类变量/静态字段

    # 实例化对象时，自动执行改方法，参数为实例方法共同拥有的参数
    def __init__(self, name, age):
        self.name = name  # 实例变量/字段
        self.age = age
        self.hobby = '看美女'

    # 实例方法--- 对象调用，自动传参
    def x1(self):
        pass

    # 类方法--- 类调用自动传参
    @classmethod
    def x2(csl):
        pass

    # 静态方法(普通函数)--- 普通的函数，需要手动传参
    @staticmethod
    def x3():
        pass


# 调用准则：静态属性由类调用，实例属性，由对象调用
# 实例化对象
obj = People(name='abc', age=18)
# 对象调用实例方法
obj.x1()
# 类调用静态字段
print(People.country)


class T2:
    def __init__(self):
        self.num = 0

    def __iter__(self):
        return self

    def __next__(self):
        self.num += 1
        if self.num == 3:
            raise StopIteration()
        return self.num


obj = T2()
v1 = next(obj)  # obj.__next__
obj2 = T2()
for item in obj2:
    print(item)  # for 循环在内部循环时，先执行__iter__获取迭代器对象，然后执行__next__,如果没有值了，抛异常


class T3:
    def __iter__(self):
        return iter([1, 2, 3])


obj3 = T3()
for item in obj3:  # 执行其__iter__ 获取迭代器
    print(item)

import functools


def outer(func):
    functools.wraps(func)  # inner.__name__ == func.__name__,inner.__doc__ ==  func.__doc__

    def inner(*args, **kwargs):
        """bbb"""
        ret = func(*args, **kwargs)
        return ret

    return inner


@outer  # auth = inner() 一旦加上装饰器，那么当前auth已经变成inner了
def auth():
    """xxx"""
    pass


ret = auth()
